package com.aigc.txt2img.utils;

import com.aigc.txt2img.exception.BaseException;
import com.aigc.txt2img.exception.ExceptionEnum;

public class ResponseUtil {
    /**
     * 响应代码
     */
    private int code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应结果
     */
    private Object data;

    public ResponseUtil() {
    }

    public ResponseUtil(BaseException exp) {
        this.code = exp.getCode();
        this.message = exp.getMessage();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static ResponseUtil success() {
        return success(null);
    }

    public static ResponseUtil success(Object data) {
        ResponseUtil ret = new ResponseUtil();
        ret.setCode(ExceptionEnum.SUCCESS.getCode());
        ret.setMessage(ExceptionEnum.SUCCESS.getMessage());
        ret.setData(data);
        return ret;
    }


    public static ResponseUtil error(BaseException error) {
        ResponseUtil ret = new ResponseUtil();
        ret.setCode(error.getCode());
        ret.setMessage(error.getMessage());
        ret.setData(null);
        return ret;
    }

    public static ResponseUtil error(int code, String msg) {
        ResponseUtil ret = new ResponseUtil();
        ret.setCode(code);
        ret.setMessage(msg);
        ret.setData(null);
        return ret;
    }

    public static ResponseUtil error(String msg) {
        ResponseUtil ret = new ResponseUtil();
        ret.setCode(ExceptionEnum.UNKNOWN.getCode());
        ret.setMessage(msg);
        ret.setData(null);
        return ret;
    }

    //    @Override
    //    public String toString() {
    //        Gson gson = new Gson();
    //        return gson.toJson(this);
    //    }

    public static void main(String[] args) {
        ResponseUtil ret = new ResponseUtil();
        ret.setCode(100);
        ret.setMessage("gson 测试");
        System.out.println(ret);
    }
}
